import React, {useEffect, useState} from 'react';
import style from './SalesroomManagement.module.scss'
import {useNavigate, useSearchParams} from "react-router-dom";
import {EditOutlined} from '@ant-design/icons'
import {collectionInfoApi,enterpriseInfoApi,getInfoApi} from '../../http/storSetApi'

function SalesroomManagement(props) {
    const navigate = useNavigate()
    const [state,setSate] =useState({
        collectionCorporateName:'',
        accountNumber:'',
        bankAdderss:'',
        depositBank:'',
        corporateName:'',
        city:'',
        adderss:'',
        longitude:'',//经度
        latitude:'',//维度
        briefIntroduction:'',
        servicePhone:'',
        Businesslicense:[],//营业执照
        DoorheadPhoto:[],//门头照片
        name:'',
        phone:'',
    })
    useEffect(()=>{
        getInfoApi(localStorage.getItem('userId'))
            .then(res=>{
                console.log(res.data.data)
                if (res.data.code== 200){
                    setSate({
                        ...state,...res.data.data
                    })
                }

            })

    },[])
    const  businesslicenseImg = state.Businesslicense.map(item=><img className={style.img} key={item.id} src={item.thumbUrl}/>)
    const  doorheadPhotoImg = state.DoorheadPhoto.map(item=><img className={style.img}key={item.id} src={item.thumbUrl}/>)

    //点击修改，跳转页面
    const jumpNavigate = (name) =>{
        console.log(name)
        //修改账号信息
        if(name=="account"){
            navigate("/user/editusername")
        }else if(name=="collection"){//修改收款信息
            navigate("/collection/edit")
        }else if(name=="enterprise"){//修改企业信息
            navigate("/enterprise/edit")
        }
    }

    return (
        <div>
            <div className={style.title}>门店设置</div>
            <div className={style.main}>
                <div className={style.itme}>
                    <div className={style.left}>登录账号</div>
                    <div className={style.right}>
                        <div className={style.right_item}>
                            {localStorage.getItem('username')}
                        </div>
                        <div  className={style.right_item_a}  onClick={()=>jumpNavigate("account")}>
                            <EditOutlined />...
                        </div>
                    </div>
                </div>
                <div className={style.itme}>
                    <div className={style.left}>收款信息</div>
                    <div className={style.right}>
                        <div  className={style.right_item_a}  onClick={()=>jumpNavigate("collection")}>
                            <EditOutlined />...
                        </div>
                    </div>
                </div>
                <div className={style.info}>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>银行开户公司名</div>
                        <div>{state.collectionCorporateName}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>银行开户账号</div>
                        <div>{state.accountNumber}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>开户银行所在地</div>
                        <div>{state.bankAdderss}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>开户银行</div>
                        <div>{state.depositBank}</div>
                    </div>
                </div>
                <div className={style.itme}>
                    <div className={style.left}>企业信息修改需要审核才能生效信息</div>
                    <div className={style.right}>
                        <div  className={style.right_item_a} onClick={()=>jumpNavigate("enterprise")}>
                            <EditOutlined />...
                        </div>
                    </div>
                </div>
                <div className={style.info}>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>企业名称</div>
                        <div>{state.corporateName}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>注册地址</div>
                        <div>{state.adderss}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>经纬度</div>
                        <div>{state.longitude + ',' +state.latitude}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>企业简介</div>
                        <div>{state.briefIntroduction}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>客服电话</div>
                        <div>{state.servicePhone}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>负责人姓名</div>
                        <div>{state.name}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>负责人电话</div>
                        <div>{state.phone}</div>
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>营业执照</div>
                        {businesslicenseImg}
                        {/*<div>{state.Businesslicense}</div>*/}
                    </div>
                    <div className={style.info_item}>
                        <div  className={style.info_item_first}>门头照片</div>
                        {doorheadPhotoImg}
                        {/*<div>{state.DoorheadPhoto}</div>*/}
                    </div>
                </div>
            </div>
        </div>
    );
}

export default SalesroomManagement;